﻿using Kingdee.BOS;
using Kingdee.BOS.Collections.Generic;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.CommonFilter;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.ListFilter;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Core.NotePrint;
using Kingdee.BOS.Core.Permission;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Orm.Metadata.DataEntity;
using Kingdee.BOS.Resource;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.ServiceHelper.Report;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
//using static Kingdee.BOS.App.Core.Validation.EntryEntity.CompositePKValidator.KeyHelper;
//using static Kingdee.BOS.Core.SqlBuilder.QueryBuilderParemeter;

namespace LianKe.DynamicFormPlugIn
{
    [Description("新增后台打印任务插件")]
    public class AddBackgroundPrintTaskPlugIn : AbstractDynamicFormPlugIn
    {
        private const string FActionTypeList = "FActionTypeId";

        private const string FFormId = "FFormId";

        private const string FSchemeList = "FSchemeId";

        private const string FOperationTypeList = "FOperationTypeId";

        private const string FExtractMethodList = "FExportMode";

        private const string FOperationTypePanel = "FOperationTypePanel";

        private const string FExtractMethodPanel = "FExtractMethodPanel";

        private const string STRSETUPINFO = "ExportSetting";

        public const string PrintAction = "Print";

        public const string PrintMergeAction = "PrintMerge";

        public const string strSetupInfo = "NotePrintSetup";

        private int exportMethodValue = 1;

        private BackgroudPrintActionType actionType;

        private string formId;

        private string formName;

        private FormMetadata formMetaData;

        private BusinessInfo formBusinessInfo;

        private List<EnumItem> filterSchemeEnumList;

        private string schemeId;

        private string schemeName;

        private NotePrintOperationType notePrintOperationType;

        private IDynamicFormView evetnProxyView;

        private JSONArray _settingInfo;

        private bool _isAdvancedSetting;

        private bool _isStandardAdvancedSetting;

        private bool _isRepotAdvancedSetting;

        private bool _isNotePrint = true;

        private int _patchPrintPage = 100;
        public JSONArray SettingInfo
        {
            get
            {
                if (_settingInfo == null)
                {
                    string text = PrintServiceHelper.LoadNotePrintPara(((AbstractDynamicFormPlugIn)this).View.Context, formId, ((AbstractDynamicFormPlugIn)this).View.Context.UserId);
                    text = StringUtils.FixedOrcalXMLString(text);
                    if (!string.IsNullOrWhiteSpace(text) && text != "<Root />")
                    {
                        _settingInfo = new JSONArray(text);
                    }
                }
                return _settingInfo;
            }
            set
            {
                _settingInfo = value;
            }
        }
        public bool IsAdvancedSetting
        {
            get
            {
                if (SettingInfo != null)
                {
                    foreach (Dictionary<string, object> item in (List<object>)(object)SettingInfo)
                    {
                        if (item.ContainsKey("enableadvantage") && item["enableadvantage"].ToString().ToLowerInvariant() == "true")
                        {
                            _isAdvancedSetting = true;
                            break;
                        }
                    }
                }
                return _isAdvancedSetting;
            }
        }

        public bool IsStandardAdvancedSetting
        {
            get
            {
                if (SettingInfo != null)
                {
                    foreach (Dictionary<string, object> item in (List<object>)(object)SettingInfo)
                    {
                        if (item.ContainsKey("standardEnableadvantage") && item["standardEnableadvantage"].ToString().ToLowerInvariant() == "true")
                        {
                            _isStandardAdvancedSetting = true;
                            break;
                        }
                    }
                }
                return _isStandardAdvancedSetting;
            }
        }

        public bool IsSysRepotAdvancedSetting
        {
            get
            {
                if (SettingInfo != null)
                {
                    foreach (Dictionary<string, object> item in (List<object>)(object)SettingInfo)
                    {
                        if (item.ContainsKey("key") && ObjectUtils.Object2String(item["key"]) == "advantageSetting" && item.ContainsKey("Enable") && ObjectUtils.Object2Bool(item["Enable"], false))
                        {
                            _isRepotAdvancedSetting = true;
                            break;
                        }
                    }
                }
                return _isRepotAdvancedSetting;
            }
        }

        protected bool IsNotePrint
        {
            get
            {
                if (SettingInfo != null)
                {
                    string text = null;
                    for (int i = 0; i < ((List<object>)(object)SettingInfo).Count; i++)
                    {
                        Dictionary<string, object> dictionary = ((List<object>)(object)SettingInfo)[i] as Dictionary<string, object>;
                        if (dictionary["key"] != null && dictionary["key"].ToString() == "printtype")
                        {
                            text = ObjectUtils.Object2String(dictionary["value"]);
                            break;
                        }
                    }
                    if (!ObjectUtils.IsNullOrEmpty((object)text) && text != "0")
                    {
                        _isNotePrint = false;
                    }
                }
                return _isNotePrint;
            }
        }

        public int BatchPrintPageCount => GetBackgroundBatchPrintCount();

        private int GetBackgroundBatchPrintCount()
        {
            int num = 0;
            object paramter = SystemParameterServiceHelper.GetParamter(((AbstractDynamicFormPlugIn)this).Context, 0L, 0L, "BOS_PlatformConfig", "BackgroundBatchPrintCount", 0L);
            num = ObjectUtils.Object2Int(paramter, 0);
            if (num == 0)
            {
                num = _patchPrintPage;
            }
            return num;
        }

        public override void BeforeUpdateValue(BeforeUpdateValueEventArgs e)
        {
            if (string.Equals(e.Key, "FFormId", StringComparison.InvariantCultureIgnoreCase))
            {
                object value = e.Value;
                DynamicObject val = (DynamicObject)((value is DynamicObject) ? value : null);
                string text = ((val == null) ? "" : val["Id"].ToString());
                if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)text) && !CheckBillRight(text))
                {
                    e.Cancel = true;
                }
            }
        }
        public override void DataChanged(DataChangedEventArgs e)
        {
            base.DataChanged(e);
            SetExportMethodShow(isShow: true);
            if (string.Equals(((AbstractElement)e.Field).Key, "FActionTypeId", StringComparison.InvariantCultureIgnoreCase))
            {
                string text = ((e.NewValue == null) ? "" : e.NewValue.ToString());
                Control control = ((AbstractDynamicFormPlugIn)this).View.GetControl("FOperationTypePanel");
                control.Visible = text == 0.ToString();
                ((AbstractDynamicFormPlugIn)this).View.UpdateView("FSchemeId");
            }
            else if (string.Equals(((AbstractElement)e.Field).Key, "FFormId", StringComparison.InvariantCultureIgnoreCase))
            {
                string selFormId = ((e.NewValue == null) ? "" : e.NewValue.ToString());
                ((AbstractDynamicFormPlugIn)this).Model.BeginIniti();
                BindSchemeList(selFormId);
                ((AbstractDynamicFormPlugIn)this).Model.EndIniti();
                ((AbstractDynamicFormPlugIn)this).View.UpdateView("FSchemeId");
            }
        }
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            string text = e.BarItemKey.ToUpperInvariant();
            string text2;
            if ((text2 = text) != null && text2 == "TBSAVE")
            {
                AddTask();
            }
        }

        private void AddTask()
        {
            actionType = (BackgroudPrintActionType)Convert.ToInt32(((AbstractDynamicFormPlugIn)this).View.Model.GetValue("FActionTypeId"));
            DynamicObject val = (DynamicObject)((AbstractDynamicFormPlugIn)this).Model.GetValue("FFormId");
            formId = val["Id"].ToString();
            formName = ((object)(LocaleValue)val["Name"]).ToString();
            schemeId = ((AbstractDynamicFormPlugIn)this).Model.GetValue("FSchemeId").ToString();
            EnumItem val2 = filterSchemeEnumList.FirstOrDefault((EnumItem o) => o.Value == schemeId);
            if (val2 != null)
            {
                //schemeName = LocaleValue.op_Implicit(val2.Caption);
                schemeName = new LocaleValue(val2.Caption);
            }
            formMetaData = FormMetaDataCache.GetCachedFormMetaData(((AbstractDynamicFormPlugIn)this).View.Context, formId);
            formBusinessInfo = formMetaData.BusinessInfo;
            notePrintOperationType = (NotePrintOperationType)(-1);
            if ((int)actionType == 0)
            {
                if (!IsNotePrint)
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("当前打印类型暂不支持", "002014000004890", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeId == 100 || ((AbstractBusinessMetadata)formMetaData).ModelTypeId == 400)
                {
                    AddListReportToTaskQueue();
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeSubId == 902)
                {
                    AddMoveReportToTaskQueue();
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeSubId == 900)
                {
                    AddSysReportToTaskQueue();
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeSubId == 903)
                {
                    AddSysReportToTaskQueue();
                    return;
                }
            }
            if ((int)actionType == 5)
            {
                if (!IsNotePrint)
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("当前打印类型暂不支持", "002014000004890", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeId == 100 || ((AbstractBusinessMetadata)formMetaData).ModelTypeId == 400)
                {
                    AddListReportNoteExportToTaskQueue();
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeSubId == 902)
                {
                    AddSysReportNoteExportToTaskQueue();
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeSubId == 900)
                {
                    AddSysReportNoteExportToTaskQueue();
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeSubId == 903)
                {
                    AddSysReportNoteExportToTaskQueue();
                    return;
                }
            }
            if ((int)actionType == 10)
            {
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeId == 100 || ((AbstractBusinessMetadata)formMetaData).ModelTypeId == 400)
                {
                    AddListExportTask(Guid.NewGuid().ToString());
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeSubId == 902)
                {
                    AddListExportTask(Guid.NewGuid().ToString());
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeSubId == 900)
                {
                    AddListExportTask(Guid.NewGuid().ToString());
                    return;
                }
                if (((AbstractBusinessMetadata)formMetaData).ModelTypeSubId == 903)
                {
                    AddListExportTask(Guid.NewGuid().ToString());
                    return;
                }
            }
        ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("当前表单类型暂不支持", "002014000004891", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
        }

        private void AddListExportTask(string taskId)
        {
            string text = formName + "-" + schemeName;
            PrintExportInfo val = new PrintExportInfo();
            val.FileType = GetSaveType(formId);
            string text2 = KDObjectConverter.SerializeObject((object)val);
            string text3 = KDObjectConverter.SerializeObject((object)((AbstractDynamicFormPlugIn)this).View.Context);
            string text4 = "{}";
            string text5 = Convert.ToString(((AbstractDynamicFormPlugIn)this).Model.GetValue("FExportMode"));
            actionType = (BackgroudPrintActionType)Convert.ToInt32(((AbstractDynamicFormPlugIn)this).View.Model.GetValue("FActionTypeId"));
            if ((int)actionType == 10)
            {
                if (string.IsNullOrEmpty(text5))
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("引出方式不能为空", "002014000006237", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                    return;
                }
            }
            else
            {
                text5 = "1";
            }
            BackgroundPrintServiceHelper.AddPrintTask(((AbstractDynamicFormPlugIn)this).View.Context, taskId, text, formId, schemeId, " ", " ", text3, text2, text4, 10, -1, text5);
            ((AbstractDynamicFormPlugIn)this).View.Close();
        }

        private ExportFileType GetSaveType(string formId)
        {
            string text = UserParamterServiceHelper.Load(((AbstractDynamicFormPlugIn)this).View.Context, "ExportSetting" + formId.ToUpperInvariant().GetHashCode(), ((AbstractDynamicFormPlugIn)this).View.Context.UserId, "");
            if (!string.IsNullOrWhiteSpace(text) && text != "<Root />")
            {
                JSONArray jsonArray = new JSONArray(text);
                string valuebyKey = GetValuebyKey(jsonArray, "filetype");
                if (!ObjectUtils.IsNullOrEmpty((object)valuebyKey))
                {
                    ExportFileType result = (ExportFileType)0;
                    if (Enum.TryParse<ExportFileType>(valuebyKey, out result))
                    {
                        return result;
                    }
                }
            }
            return (ExportFileType)0;
        }

        private string GetValuebyKey(JSONArray jsonArray, string key)
        {
            string result = string.Empty;
            if (jsonArray == null)
            {
                return result;
            }
            for (int i = 0; i < ((List<object>)(object)jsonArray).Count; i++)
            {
                Dictionary<string, object> dictionary = ((List<object>)(object)jsonArray)[i] as Dictionary<string, object>;
                if (dictionary["key"] != null && dictionary["key"].ToString() == key)
                {
                    result = ObjectUtils.Object2String(dictionary["value"]);
                    break;
                }
            }
            return result;
        }

        private void AddSysReportNoteExportToTaskQueue()
        {
            if (IsSysRepotAdvancedSetting)
            {
                string validateMsg = null;
                PrintExportInfo sysReportAdvantageExportInfo = GetSysReportAdvantageExportInfo(ref validateMsg);
                if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)validateMsg))
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(validateMsg, "", (MessageBoxType)0);
                }
                else if (sysReportAdvantageExportInfo == null)
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("没有符合条件的套打模板，请检查模板设置，然后再导出。", "002014000008770", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                }
                else
                {
                    ShowSelectExportFormat(sysReportAdvantageExportInfo);
                }
                return;
            }
            List<string> billIds = new List<string>();
            List<string> list = new List<string>();
            List<string> sortStrs = new List<string>();
            string singleNoteID = GetSingleNoteID();
            if (string.IsNullOrWhiteSpace(singleNoteID))
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("请先选择一个套打模板, 然后再导出.", "002012030025324", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return;
            }
            if (!IsNoteTemplateExist(singleNoteID))
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("当前模板不存在, 请重新选择模板, 然后再导出.", "002012030025325", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return;
            }
            list.Add(singleNoteID);
            string text = Guid.NewGuid().ToString();
            PrintExportInfo val = new PrintExportInfo();
            val.PageId = text;
            val.TaskId = text;
            val.FormId = formId;
            val.BillIds = billIds;
            val.TemplateIds = list;
            val.SortStrs = sortStrs;
            ShowSelectExportFormat(val);
        }

        private void ShowSelectExportFormat(PrintExportInfo pExInfo)
        {
            DynamicFormShowParameter val = new DynamicFormShowParameter();
            val.FormId = "BOS_SELECTEXPORTFORMATE";
            val.ParentPageId = ((AbstractDynamicFormPlugIn)this).View.PageId;
            ((AbstractDynamicFormPlugIn)this).View.ShowForm(val, (Action<FormResult>)delegate (FormResult res)
            {
                object returnData = res.ReturnData;
                JSONObject val2 = (JSONObject)((returnData is JSONObject) ? returnData : null);
                if (val2 != null)
                {
                    ExportFileType fileType = (ExportFileType)Enum.Parse(typeof(ExportFileType), val2.Get("fileType").ToString());
                    ExportType exportType = (ExportType)Convert.ToInt32(val2.Get("exportType"));
                    pExInfo.FilePath = val2.Get("filePath").ToString();
                    pExInfo.FileType = fileType;
                    pExInfo.ExportType = exportType;
                    AddNoteExportTask(pExInfo.TaskId, pExInfo);
                }
            });
        }

        private PrintExportInfo GetSysReportAdvantageExportInfo(ref string validateMsg)
        {
            PrintExportInfo result = null;
            List<AdvantageSetting> sysReportAdvantageSetting = GetSysReportAdvantageSetting(ref validateMsg);
            if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)validateMsg) || sysReportAdvantageSetting == null)
            {
                return result;
            }
            List<string> list = new List<string>();
            foreach (AdvantageSetting item in sysReportAdvantageSetting)
            {
                if (item != null && !ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)item.TemplateId))
                {
                    list.Add(item.TemplateId);
                }
            }
            if (ListUtils.IsEmpty<string>((IEnumerable<string>)list))
            {
                return result;
            }
            string text = Guid.NewGuid().ToString();
            List<string> billIds = new List<string>();
            List<string> sortStrs = new List<string>();
            result = new PrintExportInfo();
            result.PageId = text;
            result.TaskId = text;
            result.FormId = formId;
            result.BillIds = billIds;
            result.TemplateIds = list;
            result.SortStrs = sortStrs;
            return result;
        }

        private void AddListReportNoteExportToTaskQueue()
        {
            List<string> list = new List<string>();
            List<string> list2 = new List<string>();
            List<string> list3 = new List<string>();
            IListView val = CreateListView(((AbstractDynamicFormPlugIn)this).View.Context, formId, schemeId);
            if (((IListModelService)val.Model).GetRowCount(((IListModelService)val.Model).TableName) <= 0)
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("没有可以导出的数据。", "002014000004484", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return;
            }
            string[] array = GetAllAllowPKs(val).ToArray();
            if (array.Length == 0)
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("没有可以打印的数据,请您确认拥有该数据的打印权限。", "002012030003436", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return;
            }
            if (IsAdvancedSetting)
            {
                List<string> billIDs = array.ToList();
                List<AdvantageSetting> advantageSetting = GetAdvantageSetting();
                foreach (AdvantageSetting item2 in advantageSetting)
                {
                    string[] array2 = ValidateByFilter(formBusinessInfo.GetForm(), billIDs, item2.FilterString);
                    if (array2 != null && array2.Length != 0)
                    {
                        string[] array3 = array2;
                        foreach (string item in array3)
                        {
                            list.Add(item);
                            list2.Add(item2.TemplateId);
                            list3.Add(item2.EtySortSql);
                        }
                    }
                }
            }
            else
            {
                list = array.ToList();
                List<ValidationResult> failResults;
                string[] batchTemplateIDs = GetBatchTemplateIDs(array.ToArray(), out failResults);
                list2 = batchTemplateIDs.ToList();
                if (failResults != null && list2.Count == 1 && failResults.Count == 1)
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(failResults.First().Message, "", (MessageBoxType)0);
                    return;
                }
                if (list2.Count == 0)
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("请选择一个套打模板,请设置后再导出.", "002012030026868", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                    return;
                }
                if (!list2.Any((string o) => !string.IsNullOrWhiteSpace(o)))
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("您选择的数据都没有设置套打模板,请设置后再导出.", "002012030026869", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                    return;
                }
            }
            string taskId = Guid.NewGuid().ToString();
            PrintExportInfo pExInfo = new PrintExportInfo();
            pExInfo.PageId = taskId;
            pExInfo.TaskId = taskId;
            pExInfo.FormId = formId;
            pExInfo.BillIds = list;
            pExInfo.TemplateIds = list2;
            pExInfo.SortStrs = list3;
            DynamicFormShowParameter val2 = new DynamicFormShowParameter();
            val2.FormId = "BOS_SELECTEXPORTFORMATE";
            val2.ParentPageId = ((AbstractDynamicFormPlugIn)this).View.PageId;
            ((AbstractDynamicFormPlugIn)this).View.ShowForm(val2, (Action<FormResult>)delegate (FormResult res)
            {
                object returnData = res.ReturnData;
                JSONObject val3 = (JSONObject)((returnData is JSONObject) ? returnData : null);
                if (val3 != null)
                {
                    ExportFileType fileType = (ExportFileType)Enum.Parse(typeof(ExportFileType), val3.Get("fileType").ToString());
                    ExportType exportType = (ExportType)Convert.ToInt32(val3.Get("exportType"));
                    pExInfo.FilePath = val3.Get("filePath").ToString();
                    pExInfo.FileType = fileType;
                    pExInfo.ExportType = exportType;
                    AddNoteExportTask(taskId, pExInfo);
                }
            });
        }

        private void AddNoteExportTask(string taskId, PrintExportInfo pExInfo)
        {
            string text = formName + "-" + schemeName;
            string text2 = KDObjectConverter.SerializeObject((object)pExInfo);
            string text3 = KDObjectConverter.SerializeObject((object)((AbstractDynamicFormPlugIn)this).View.Context);
            string text4 = "{}";
            BackgroundPrintServiceHelper.AddPrintTask(((AbstractDynamicFormPlugIn)this).View.Context, taskId, text, formId, schemeId, " ", " ", text3, text2, text4, 5, -1, "1");
            ((AbstractDynamicFormPlugIn)this).View.Close();
        }

        public string[] GetBatchTemplateIDs(string[] arrbillIds, out List<ValidationResult> failResults)
        {
            failResults = new List<ValidationResult>();
            BillTypeField billTypeField = formBusinessInfo.GetBillTypeField();
            BillStatusField billStatusField = formBusinessInfo.GetBillStatusField();
            Field billNoField = formBusinessInfo.GetBillNoField();
            Form form = formBusinessInfo.GetForm();
            string pkFieldName = form.PkFieldName;
            Dictionary<string, bool> dictionary = new Dictionary<string, bool>();
            DynamicObjectCollection statusBillTypeObjs = GetStatusBillTypeObjs(arrbillIds, billTypeField, billStatusField, billNoField);
            string[] array = new string[arrbillIds.Count()];
            string empty = string.Empty;
            for (int i = 0; i < arrbillIds.Count(); i++)
            {
                string currentBillId = arrbillIds[i];
                DynamicObject val = null;
                if (statusBillTypeObjs != null)
                {
                    val = ((IEnumerable<DynamicObject>)statusBillTypeObjs).Where((DynamicObject p) => p[pkFieldName].ToString().Equals(currentBillId)).FirstOrDefault();
                }
                string billTypeID = string.Empty;
                if (billTypeField != null && val != null)
                {
                    billTypeID = val[((AbstractElement)billTypeField).Key].ToString();
                }
                empty = GetTemplateIdFromSetting(billTypeID);
                if (!ObjectUtils.IsNullOrEmpty((object)billTypeID) && ObjectUtils.IsNullOrEmpty((object)empty))
                {
                    DynamicObject val2 = billTypeField.BillTypeInfo.Find((DynamicObject p) => p["Id"].ToString().Equals(billTypeID));
                    if (val2 != null)
                    {
                        empty = ((val2["DefPrintTemplate"] == null) ? string.Empty : val2["DefPrintTemplate"].ToString());
                    }
                }
                if (ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)empty))
                {
                    empty = ((AbstractDynamicFormPlugIn)this).View.BillBusinessInfo.GetForm().Note;
                }
                bool value = false;
                if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)empty))
                {
                    if (!dictionary.Keys.Contains(empty))
                    {
                        value = IsNoteTemplateExist(empty);
                        dictionary.Add(empty, value);
                    }
                    else
                    {
                        dictionary.TryGetValue(empty, out value);
                    }
                }
                if (value)
                {
                    array[i] = empty;
                }
                else
                {
                    array[i] = string.Empty;
                }
            }
            return array;
        }

        private void AddSysReportToTaskQueue()
        {
            string taskId = Guid.NewGuid().ToString();
            string text = "";
            if (IsSysRepotAdvancedSetting)
            {
                string validateMsg = null;
                List<PrintJob> sysReportAdvantagePrintJobs = GetSysReportAdvantagePrintJobs(taskId, text, ref validateMsg);
                if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)validateMsg))
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(validateMsg, "", (MessageBoxType)0);
                }
                else if (ListUtils.IsEmpty<PrintJob>((IEnumerable<PrintJob>)sysReportAdvantagePrintJobs))
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("请选择一个套打模板,然后再打印预览操作.", "002012030003091", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                }
                else
                {
                    AddPrintTask(taskId, sysReportAdvantagePrintJobs);
                }
                return;
            }
            string singleNoteID = GetSingleNoteID();
            if (string.IsNullOrWhiteSpace(singleNoteID))
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("请选择一个套打模板,然后再打印预览操作.", "002012030003091", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return;
            }
            if (!IsNoteTemplateExist(singleNoteID))
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("当前模板不存在, 请重新选择模板, 然后再打印预览操作.", "002012030003469", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return;
            }
            List<PrintJobItem> list = new List<PrintJobItem>();
            PrintJobItem val = new PrintJobItem(text, singleNoteID);
            val.IsBackgroundPrintTask = true;
            list.Add(val);
            PrintJob val2 = new PrintJob();
            val2.Id = taskId;
            val2.FormId = formId;
            list.ForEach(delegate (PrintJobItem p)
            {
                p.PrintJobId = taskId;
            });
            val2.PrintJobItems = list;
            val2.BatchPrintPageCount = BatchPrintPageCount;
            List<PrintJob> list2 = new List<PrintJob>();
            list2.Add(val2);
            AddPrintTask(taskId, list2);
        }

        private void AddMoveReportToTaskQueue()
        {
            string taskId = Guid.NewGuid().ToString();
            string text = "allMoveReportData";
            if (IsSysRepotAdvancedSetting)
            {
                string validateMsg = null;
                List<PrintJob> sysReportAdvantagePrintJobs = GetSysReportAdvantagePrintJobs(taskId, text, ref validateMsg);
                if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)validateMsg))
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(validateMsg, "", (MessageBoxType)0);
                }
                else if (ListUtils.IsEmpty<PrintJob>((IEnumerable<PrintJob>)sysReportAdvantagePrintJobs))
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("请选择一个套打模板,然后再打印预览操作.", "002012030003091", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                }
                else
                {
                    AddPrintTask(taskId, sysReportAdvantagePrintJobs);
                }
                return;
            }
            string singleNoteID = GetSingleNoteID();
            if (string.IsNullOrWhiteSpace(singleNoteID))
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("请选择一个套打模板,然后再打印预览操作.", "002012030003091", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return;
            }
            if (!IsNoteTemplateExist(singleNoteID))
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("当前模板不存在, 请重新选择模板, 然后再打印预览操作.", "002012030003469", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return;
            }
            List<PrintJobItem> list = new List<PrintJobItem>();
            PrintJobItem val = new PrintJobItem(text, singleNoteID);
            val.IsBackgroundPrintTask = true;
            list.Add(val);
            PrintJob val2 = new PrintJob();
            val2.Id = taskId;
            val2.FormId = formId;
            list.ForEach(delegate (PrintJobItem p)
            {
                p.PrintJobId = taskId;
            });
            val2.PrintJobItems = list;
            val2.BatchPrintPageCount = BatchPrintPageCount;
            List<PrintJob> list2 = new List<PrintJob>();
            list2.Add(val2);
            AddPrintTask(taskId, list2);
        }

        public string GetSingleNoteID()
        {
            string text = string.Empty;
            if (SettingInfo != null)
            {
                foreach (Dictionary<string, object> item in (List<object>)(object)SettingInfo)
                {
                    if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace(item["key"]) && item["key"].Equals("reportNote") && !ObjectUtils.IsNullOrEmptyOrWhiteSpace(item["value"]) && !item["value"].Equals("empty"))
                    {
                        text = item["value"].ToString();
                        break;
                    }
                    if (ObjectUtils.IsNullOrEmptyOrWhiteSpace(item["key"]) && !ObjectUtils.IsNullOrEmptyOrWhiteSpace(item["value"]) && !item["value"].Equals("empty"))
                    {
                        text = item["value"].ToString();
                    }
                }
            }
            if (ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)text))
            {
                text = formBusinessInfo.GetForm().Note;
            }
            return text;
        }

        private List<PrintJob> GetSysReportAdvantagePrintJobs(string taskId, string billId, ref string validateMsg)
        {
            List<PrintJob> list = new List<PrintJob>();
            List<AdvantageSetting> sysReportAdvantageSetting = GetSysReportAdvantageSetting(ref validateMsg);
            if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)validateMsg) || sysReportAdvantageSetting == null)
            {
                return list;
            }
            foreach (AdvantageSetting item2 in sysReportAdvantageSetting)
            {
                if (item2 != null)
                {
                    List<PrintJobItem> list2 = new List<PrintJobItem>();
                    PrintJobItem val = new PrintJobItem(billId, item2.TemplateId);
                    val.IsBackgroundPrintTask = true;
                    val.UsePaperInfo = item2.UsePaperInfo;
                    val.PrintJobId = taskId;
                    list2.Add(val);
                    PrintJob val2 = new PrintJob();
                    val2.Id = taskId;
                    val2.FormId = formId;
                    val2.IsEconomizePaper = item2.IsEconomizePaper;
                    val2.PrintJobItems = list2;
                    val2.BatchPrintPageCount = BatchPrintPageCount;
                    val2.Printer = item2.Printer;
                    PrintJob item = val2;
                    list.Add(item);
                }
            }
            return list;
        }

        public List<AdvantageSetting> GetSysReportAdvantageSetting(ref string validateMsg)
        {
            List<AdvantageSetting> list = new List<AdvantageSetting>();
            if (ListUtils.IsEmpty<object>((IEnumerable<object>)SettingInfo))
            {
                return list;
            }
            RequestTemplateParam val = new RequestTemplateParam();
            val.FormId = formId;
            val.IsAddEmptyItem = false;
            val.IsFireGetValidNoteTemplatesPlugIn = false;
            val.IsNoteStatementSetup = true;
            RequestTemplateParam val2 = val;
            List<EnumItem> enableNotePrintTemplate = PrintServiceHelper.GetEnableNotePrintTemplate(((AbstractDynamicFormPlugIn)this).View.Context, val2);
            foreach (Dictionary<string, object> item in (List<object>)(object)SettingInfo)
            {
                if (item.ContainsKey("key") && ObjectUtils.Object2String(item["key"]) == "advantageSetting" && item.ContainsKey("Enable") && ObjectUtils.Object2Bool(item["Enable"], false) && item.ContainsKey("TemplateId") && !ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)ObjectUtils.Object2String(item["TemplateId"])))
                {
                    string templateId = ObjectUtils.Object2String(item["TemplateId"]);
                    AdvantageSetting val3 = new AdvantageSetting();
                    val3.TemplateId = templateId;
                    val3.Printer = (item.ContainsKey("Printer") ? ObjectUtils.Object2String(item["Printer"]) : string.Empty);
                    val3.IsEconomizePaper = item.ContainsKey("IsEconomizePaper") && ObjectUtils.Object2Bool(item["IsEconomizePaper"], false);
                    list.Add(val3);
                }
            }
            if (!ListUtils.IsEmpty<AdvantageSetting>((IEnumerable<AdvantageSetting>)list) && !ListUtils.IsEmpty<EnumItem>((IEnumerable<EnumItem>)enableNotePrintTemplate))
            {
                string[] array = list.Select((AdvantageSetting p) => p.TemplateId).ToArray();
                AbstractBusinessMetadata obj = MetaDataServiceHelper.Load(((AbstractDynamicFormPlugIn)this).Context, "BOS_ObjectType", true);
                FormMetadata val4 = (FormMetadata)(object)((obj is FormMetadata) ? obj : null);
                BusinessInfo businessInfo = val4.BusinessInfo;
                List<string> list2 = new List<string>();
                list2.Add("FID");
                List<string> list3 = list2;
                Field field = businessInfo.GetField("FName");
                if (field != null)
                {
                    list3.Add(((AbstractElement)field).Key);
                }
                DynamicObjectType dynamicObjectType = businessInfo.GetSubBusinessInfo(list3).GetDynamicObjectType();
                DynamicObject[] array2 = BusinessDataServiceHelper.Load(((AbstractDynamicFormPlugIn)this).View.Context, (object[])array, dynamicObjectType);
                if (!ListUtils.IsEmpty<DynamicObject>((IEnumerable<DynamicObject>)array2))
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    DynamicObject[] array3 = array2;
                    foreach (DynamicObject val5 in array3)
                    {
                        if (val5 != null)
                        {
                            string fid = ObjectUtils.Object2String(val5["Id"]);
                            if (!enableNotePrintTemplate.Any((EnumItem p) => p.EnumId == fid))
                            {
                                string arg = ((field == null || ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)field.PropertyName)) ? fid : ObjectUtils.Object2String(val5[field.PropertyName]));
                                stringBuilder.AppendFormat("【{0}】、", arg);
                            }
                        }
                    }
                    if (stringBuilder.Length > 0)
                    {
                        validateMsg = string.Format(ResManager.LoadKDString("模板：{0}不可用，请检查相关模板设置。", "002014000008769", (SubSystemType)2, new object[0]), stringBuilder.Remove(stringBuilder.Length - 1, 1).ToString());
                    }
                }
            }
            return list;
        }

        private void AddListReportToTaskQueue()
        {
            notePrintOperationType = (NotePrintOperationType)0;
            object value = ((AbstractDynamicFormPlugIn)this).Model.GetValue("FOperationTypeId");
            if (value != null && !ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)value.ToString()))
            {
                notePrintOperationType = (NotePrintOperationType)Convert.ToInt32(value);
            }
            if ((int)notePrintOperationType == 0)
            {
                AddListNoteReportToTaskQueue("Print");
            }
            else if ((int)notePrintOperationType == 5)
            {
                AddListNoteReportToTaskQueue("PrintMerge");
            }
        }

        private void AddListNoteReportToTaskQueue(string printType)
        {
            IListView val = CreateListView(((AbstractDynamicFormPlugIn)this).View.Context, formId, schemeId);
            if (((IListModelService)val.Model).GetRowCount(((IListModelService)val.Model).TableName) <= 0)
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("没有可以打印的数据。", "002012030003433", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return;
            }
            string[] array = GetAllAllowPKs(val).ToArray();
            if (array.Length == 0)
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("没有可以打印的数据,请您确认拥有该数据的打印权限。", "002012030003436", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return;
            }
            evetnProxyView = CreateView(((AbstractDynamicFormPlugIn)this).Context, formId);
            if (SelectTemplateParm())
            {
                DynamicFormViewPlugInProxy service = ((IDynamicFormView)val).GetService<DynamicFormViewPlugInProxy>();
                ListNoteReportDoInteractiveAction(service, array, printType, isSelectedEtyId: false);
            }
            else if (IsAdvancedSetting)
            {
                ListNoteReportDoAdvancedAction(array, printType);
            }
            else
            {
                ListNoteReportDoNormalAction(array, printType);
            }
        }

        public virtual void ListNoteReportDoNormalAction(string[] billIDs, string printType, bool isGetSelectedEtyId = false)
        {
            //IL_00a0: Unknown result type (might be due to invalid IL or missing references)
            //IL_00a7: Expected O, but got Unknown
            string taskId = Guid.NewGuid().ToString();
            List<ValidationResult> failResults;
            List<PrintJobItem> normalPrintJobItems = GetNormalPrintJobItems(billIDs, isGetSelectedEtyId, out failResults);
            if (billIDs.Length > 0 && normalPrintJobItems.Count == 0)
            {
                string text = string.Empty;
                foreach (ValidationResult item in failResults)
                {
                    text = text + item.Message + "\r\n";
                }
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(text, "", (MessageBoxType)0);
            }
            else if (normalPrintJobItems.Count > 0)
            {
                PrintJob val = new PrintJob();
                val.Id = taskId;
                val.FormId = formId;
                normalPrintJobItems.ForEach(delegate (PrintJobItem p)
                {
                    p.PrintJobId = taskId;
                });
                val.PrintJobItems = normalPrintJobItems;
                if (StringUtils.EqualsIgnoreCase(printType, "PrintMerge"))
                {
                    val.IsMergedPrint = true;
                }
                val.BatchPrintPageCount = BatchPrintPageCount;
                List<PrintJob> list = new List<PrintJob>();
                list.Add(val);
                AddPrintTask(taskId, list);
            }
            else
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("没有符合条件的数据", "002012030026833", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
            }
        }

        public List<PrintJobItem> GetNormalPrintJobItems(string[] arrbillIds, bool isGetSelectedEtyId, out List<ValidationResult> failResults)
        {
            List<PrintJobItem> list = new List<PrintJobItem>();
            Dictionary<string, bool> dictionary = new Dictionary<string, bool>();
            Form form = formBusinessInfo.GetForm();
            string pkFieldName = form.PkFieldName;
            BillTypeField billTypeField = formBusinessInfo.GetBillTypeField();
            BillStatusField billStatusField = formBusinessInfo.GetBillStatusField();
            Field billNoField = formBusinessInfo.GetBillNoField();
            DynamicObjectCollection statusBillTypeObjs = GetStatusBillTypeObjs(arrbillIds, billTypeField, billStatusField, billNoField);
            failResults = new List<ValidationResult>();
            List<ValidationResult> list2 = CheckBatchPrint(arrbillIds);
            if (list2 == null)
            {
                return list;
            }
            foreach (ValidationResult item in list2)
            {
                if (!item.IsSuccess)
                {
                    failResults.Add(item);
                    continue;
                }
                string currentBillId = item.BillId;
                DynamicObject val = null;
                if (statusBillTypeObjs != null)
                {
                    val = ((IEnumerable<DynamicObject>)statusBillTypeObjs).Where((DynamicObject p) => p[pkFieldName].ToString().Equals(currentBillId)).FirstOrDefault();
                }
                string billTypeID = string.Empty;
                if (billTypeField != null && val != null && ((KeyedCollectionBase<string, DynamicProperty>)(object)val.DynamicObjectType.Properties).ContainsKey(((AbstractElement)billTypeField).Key))
                {
                    billTypeID = val[((AbstractElement)billTypeField).Key].ToString();
                }
                string text = GetTemplateIdFromSetting(billTypeID);
                if (!ObjectUtils.IsNullOrEmpty((object)billTypeID) && ObjectUtils.IsNullOrEmpty((object)text))
                {
                    DynamicObject val2 = billTypeField.BillTypeInfo.Find((DynamicObject p) => p["Id"].ToString().Equals(billTypeID));
                    if (val2 != null)
                    {
                        text = ((val2["DefPrintTemplate"] == null) ? string.Empty : val2["DefPrintTemplate"].ToString());
                    }
                }
                if (ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)text))
                {
                    text = formBusinessInfo.GetForm().Note;
                }
                if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)text))
                {
                    bool value = false;
                    if (!dictionary.Keys.Contains(text))
                    {
                        value = IsNoteTemplateExist(text);
                        dictionary.Add(text, value);
                    }
                    else
                    {
                        dictionary.TryGetValue(text, out value);
                    }
                    if (value)
                    {
                        PrintJobItem val3 = new PrintJobItem(currentBillId, text, billTypeID);
                        val3.IgnoreVerification = item.ValidateIgnoreType;
                        val3.IsBackgroundPrintTask = true;
                        list.Add(val3);
                        continue;
                    }
                    ValidationResult val4 = new ValidationResult();
                    string message = ResManager.LoadKDString("模板不可用，请重新设置模板。", "002014030032776", (SubSystemType)2, new object[0]);
                    if (!failResults.Exists((ValidationResult o) => StringUtils.EqualsIgnoreCase(o.Message, message)))
                    {
                        val4.Message = message;
                        failResults.Add(val4);
                    }
                }
                else
                {
                    ValidationResult val5 = new ValidationResult();
                    string message2 = ResManager.LoadKDString("当前对象没有配置套打模板，请先到【套打设置】页面配置套打模板", "002012000006656", (SubSystemType)2, new object[0]);
                    if (!failResults.Exists((ValidationResult o) => StringUtils.EqualsIgnoreCase(o.Message, message2)))
                    {
                        val5.Message = message2;
                        failResults.Add(val5);
                    }
                }
            }
            return list;
        }

        public bool IsNoteTemplateExist(string templateId)
        {
            //IL_000f: Unknown result type (might be due to invalid IL or missing references)
            //IL_0015: Expected O, but got Unknown
            bool result = false;
            string text = "select 1 from T_META_OBJECTTYPE WHERE FID=@FID";
            SqlParam item = new SqlParam("@FID", (KDDbType)0, (object)templateId);
            using (IDataReader dataReader = DBServiceHelper.ExecuteReader(((AbstractDynamicFormPlugIn)this).View.Context, text, new List<SqlParam> { item }))
            {
                if (dataReader.Read())
                {
                    result = true;
                }
            }
            return result;
        }

        private string GetTemplateIdFromSetting(string billTypeId)
        {
            string result = string.Empty;
            if (SettingInfo != null)
            {
                if (ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)billTypeId))
                {
                    for (int i = 0; i < ((List<object>)(object)SettingInfo).Count - 1; i++)
                    {
                        Dictionary<string, object> dictionary = ((List<object>)(object)SettingInfo)[i] as Dictionary<string, object>;
                        if (dictionary.ContainsKey("value") && !ObjectUtils.IsNullOrEmptyOrWhiteSpace(dictionary["value"]) && !dictionary["value"].Equals("empty") && (dictionary["key"] == null || string.IsNullOrWhiteSpace(dictionary["key"].ToString())))
                        {
                            result = ((dictionary["value"] == null) ? string.Empty : dictionary["value"].ToString());
                            break;
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < ((List<object>)(object)SettingInfo).Count - 1; j++)
                    {
                        Dictionary<string, object> dictionary2 = ((List<object>)(object)SettingInfo)[j] as Dictionary<string, object>;
                        if (dictionary2["key"] != null && dictionary2["key"].Equals(billTypeId))
                        {
                            result = ((dictionary2["value"] == null) ? string.Empty : dictionary2["value"].ToString());
                            break;
                        }
                    }
                }
            }
            return result;
        }

        private void ListNoteReportDoAdvancedAction(string[] billIDs, string printType, bool isGetSelectedEtyId = false, string printOptName = null)
        {
            string taskId = Guid.NewGuid().ToString();
            List<PrintJob> list = new List<PrintJob>();
            List<AdvantageSetting> advantageSetting = GetAdvantageSetting();
            List<string> list2 = billIDs.ToList();
            List<ValidationResult> list3 = CheckBatchPrint(billIDs);
            Dictionary<string, ValidationResult> dictionary = new Dictionary<string, ValidationResult>();
            foreach (ValidationResult item in list3)
            {
                if (!dictionary.ContainsKey(item.BillId))
                {
                    dictionary[item.BillId] = item;
                }
            }
            foreach (AdvantageSetting item2 in advantageSetting)
            {
                string[] array = ValidateByFilter(formBusinessInfo.GetForm(), list2, item2.FilterString);
                if (array == null || array.Length == 0)
                {
                    continue;
                }
                List<ValidationResult> list4 = new List<ValidationResult>();
                string[] array2 = array;
                foreach (string key in array2)
                {
                    if (dictionary.ContainsKey(key) && dictionary[key].IsSuccess)
                    {
                        list4.Add(dictionary[key]);
                    }
                }
                if (list4.Count == 0)
                {
                    continue;
                }
                List<PrintJobItem> list5 = new List<PrintJobItem>();
                foreach (ValidationResult item3 in list4)
                {
                    if (!item3.IsControlPrintCount || item3.MaxPrintCount == 0 || item3.PrintedCount != item3.MaxPrintCount)
                    {
                        PrintJobItem val = new PrintJobItem(item3.BillId, item2.TemplateId, item3.BillTypeId);
                        val.EtySortSql = item2.EtySortSql;
                        val.IsBackgroundPrintTask = true;
                        list5.Add(val);
                        if (item3.MaxPrintCount - item3.PrintedCount == 1)
                        {
                            list2.Remove(item3.BillId);
                        }
                        item3.PrintedCount += 1;
                    }
                }
                if (list5.Count > 0)
                {
                    PrintJob val2 = new PrintJob();
                    val2.Id = taskId;
                    val2.FormId = formId;
                    val2.Printer = item2.Printer;
                    val2.IsEconomizePaper = item2.IsEconomizePaper;
                    list5.ForEach(delegate (PrintJobItem p)
                    {
                        p.PrintJobId = taskId;
                    });
                    val2.PrintJobItems = list5;
                    if (StringUtils.EqualsIgnoreCase(printType, "PrintMerge"))
                    {
                        val2.IsMergedPrint = true;
                    }
                    val2.BatchPrintPageCount = BatchPrintPageCount;
                    list.Add(val2);
                }
            }
            if (list.Count == 0)
            {
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("没有符合条件的数据", "002012030026833", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
            }
            else
            {
                AddPrintTask(taskId, list);
            }
        }

        public string[] ValidateByFilter(Form form, List<string> billIDs, string filterString)
        {
            if (ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)filterString))
            {
                return Enumerable.ToArray(billIDs);
            }
            string pkFieldName = form.PkFieldName;
            QueryBuilderParemeter val = new QueryBuilderParemeter();
            val.FormId = ((AbstractElement)form).Id;
            val.SelectItems.Add(new SelectorItemInfo(pkFieldName));
            val.FilterClauseWihtKey = filterString;
            DynamicObjectCollection printDataByTemporaryTable = PrintServiceHelper.GetPrintDataByTemporaryTable(((AbstractDynamicFormPlugIn)this).View.Model.Context, val, string.Join(",", billIDs.ToArray()), pkFieldName, form.PkFieldType);
            if (printDataByTemporaryTable != null && ((Collection<DynamicObject>)(object)printDataByTemporaryTable).Count > 0)
            {
                string[] array = new string[((Collection<DynamicObject>)(object)printDataByTemporaryTable).Count];
                for (int i = 0; i < ((Collection<DynamicObject>)(object)printDataByTemporaryTable).Count; i++)
                {
                    array[i] = ((Collection<DynamicObject>)(object)printDataByTemporaryTable)[i][pkFieldName].ToString();
                }
                return array;
            }
            return null;
        }

        public List<AdvantageSetting> GetAdvantageSetting()
        {
            List<AdvantageSetting> list = new List<AdvantageSetting>();
            foreach (Dictionary<string, object> item in (List<object>)(object)SettingInfo)
            {
                if (item.ContainsKey("enableadvantage") && StringUtils.EqualsIgnoreCase(item["enableadvantage"].ToString(), "true") && !ObjectUtils.IsNullOrEmptyOrWhiteSpace(item["templateValue"]))
                {
                    AdvantageSetting val = new AdvantageSetting();
                    val.EtySortSql = ((item["sortsqlString"] == null) ? "" : item["sortsqlString"].ToString());
                    val.FilterString = ((item["filter"] == null) ? "" : item["filter"].ToString());
                    val.Printer = ((item["printerFID"] == null) ? "" : item["printerFID"].ToString());
                    val.TemplateId = item["templateValue"].ToString();
                    if (item.ContainsKey("economizePaper"))
                    {
                        val.IsEconomizePaper = item["economizePaper"] != null && (bool)item["economizePaper"];
                    }
                    list.Add(val);
                }
            }
            return list;
        }

        internal void ListNoteReportDoInteractiveAction(DynamicFormViewPlugInProxy plugInProxy, string[] billIDs, string printType, bool isSelectedEtyId)
        {
            //IL_0023: Unknown result type (might be due to invalid IL or missing references)
            //IL_0029: Expected O, but got Unknown
            DynamicFormShowParameter val = new DynamicFormShowParameter();
            val.FormId = "BOS_SelectNoteTemplate";
            val.ParentPageId = ((AbstractDynamicFormPlugIn)this).View.PageId;
            val.CustomParams.Add("formId", formId);
            if (plugInProxy != null)
            {
                val.CustomComplexParams["NoteTemplatePlugIn"] = plugInProxy;
            }
        ((AbstractDynamicFormPlugIn)this).View.ShowForm(val, (Action<FormResult>)delegate (FormResult res)
        {
            //IL_00c7: Unknown result type (might be due to invalid IL or missing references)
            //IL_00cd: Expected O, but got Unknown
            if (res.ReturnData is List<string> returnTmps)
            {
                List<ValidationResult> failResults;
                List<PrintJobItem> interactiveJobItems = GetInteractiveJobItems(formBusinessInfo.GetForm(), billIDs, returnTmps, isSelectedEtyId, out failResults);
                if (interactiveJobItems.Count == 0)
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(failResults[0].Message, "", (MessageBoxType)0);
                }
                else if (interactiveJobItems.Count == 1 && failResults.Count == 1)
                {
                    ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(failResults[0].Message, "", (MessageBoxType)0);
                }
                else
                {
                    string taskId = Guid.NewGuid().ToString();
                    PrintJob val2 = new PrintJob();
                    val2.Id = taskId;
                    val2.FormId = formId;
                    interactiveJobItems.ForEach(delegate (PrintJobItem p)
                    {
                        p.PrintJobId = taskId;
                    });
                    val2.PrintJobItems = interactiveJobItems;
                    if (StringUtils.EqualsIgnoreCase(printType, "PrintMerge"))
                    {
                        val2.IsMergedPrint = true;
                    }
                    val2.BatchPrintPageCount = BatchPrintPageCount;
                    List<PrintJob> jobs = new List<PrintJob> { val2 };
                    AddPrintTask(taskId, jobs);
                }
            }
        });
        }

        private void AddPrintTask(string taskId, List<PrintJob> jobs)
        {
            string text = formName + "-" + schemeName;
            string text2 = KDObjectConverter.SerializeObject((object)jobs);
            string text3 = KDObjectConverter.SerializeObject((object)((AbstractDynamicFormPlugIn)this).View.Context);
            string text4 = "{}";
            BackgroundPrintServiceHelper.AddPrintTask(((AbstractDynamicFormPlugIn)this).View.Context, taskId, text, formId, schemeId, " ", " ", text3, text2, text4, 0, (int)notePrintOperationType, "1");
            ((AbstractDynamicFormPlugIn)this).View.Close();
        }

        public List<PrintJobItem> GetInteractiveJobItems(Form form, string[] arrbillIds, List<string> returnTmps, bool isSelectedEtyId, out List<ValidationResult> failResults)
        {
            List<PrintJobItem> list = new List<PrintJobItem>();
            _ = form.PkFieldName;
            BillTypeField billTypeField = formBusinessInfo.GetBillTypeField();
            BillStatusField billStatusField = formBusinessInfo.GetBillStatusField();
            Field billNoField = formBusinessInfo.GetBillNoField();
            GetStatusBillTypeObjs(arrbillIds, billTypeField, billStatusField, billNoField);
            failResults = new List<ValidationResult>();
            List<ValidationResult> list2 = CheckBatchPrint(arrbillIds);
            if (list2 == null)
            {
                return list;
            }
            foreach (ValidationResult item in list2)
            {
                if (!item.IsSuccess)
                {
                    failResults.Add(item);
                    continue;
                }
                if (item.IsControlPrintCount)
                {
                    int maxPrintCount = item.MaxPrintCount;
                    int num = item.PrintedCount;
                    foreach (string returnTmp in returnTmps)
                    {
                        if (num <= maxPrintCount)
                        {
                            PrintJobItem val = new PrintJobItem(item.BillId, returnTmp);
                            val.IgnoreVerification = item.ValidateIgnoreType;
                            list.Add(val);
                            val.IsBackgroundPrintTask = true;
                            num++;
                        }
                    }
                    continue;
                }
                foreach (string returnTmp2 in returnTmps)
                {
                    PrintJobItem val2 = new PrintJobItem(item.BillId, returnTmp2);
                    val2.IgnoreVerification = item.ValidateIgnoreType;
                    val2.IsBackgroundPrintTask = true;
                    list.Add(val2);
                }
            }
            return list;
        }

        public List<ValidationResult> CheckBatchPrint(string[] billIds)
        {
            List<ValidationResult> list = new List<ValidationResult>();
            if (evetnProxyView != null)
            {
                DynamicFormViewPlugInProxy service = evetnProxyView.GetService<DynamicFormViewPlugInProxy>();
                BeforePrintValidateEventArgs val = new BeforePrintValidateEventArgs(billIds);
                service.FireBeforePrintValidate(val);
                if (val.ValidateInfos != null && val.ValidateInfos.Count > 0)
                {
                    list = PrintServiceHelper.BatchValidatePrintControl(((AbstractDynamicFormPlugIn)this).View.Context, formBusinessInfo, val.ValidateInfos);
                }
            }
            else
            {
                BillTypeField billTypeField = formBusinessInfo.GetBillTypeField();
                BillStatusField billStatusField = formBusinessInfo.GetBillStatusField();
                Field billNoField = formBusinessInfo.GetBillNoField();
                Form form = formBusinessInfo.GetForm();
                string pkFieldName = form.PkFieldName;
                new List<string>();
                DynamicObjectCollection statusBillTypeObjs = GetStatusBillTypeObjs(billIds, billTypeField, billStatusField, billNoField);
                foreach (string billId in billIds)
                {
                    DynamicObject obj = null;
                    if (statusBillTypeObjs != null)
                    {
                        obj = ((IEnumerable<DynamicObject>)statusBillTypeObjs).Where((DynamicObject p) => p[pkFieldName].ToString().Equals(billId)).FirstOrDefault();
                    }
                    ValidationResult val2 = CheckSinglePrint(billId, obj, billTypeField, billStatusField);
                    if (val2.IsSuccess)
                    {
                        list.Add(val2);
                    }
                }
            }
            return list;
        }

        private ValidationResult CheckSinglePrint(string billId, DynamicObject obj, BillTypeField billTypeField, BillStatusField billStatusField)
        {
            ValidationResult result = null;
            if (obj == null)
            {
                result = new ValidationResult();
                result.BillId = billId;
                return result;
            }
            if (string.IsNullOrEmpty(billId))
            {
                return result;
            }
            string text = string.Empty;
            string text2 = string.Empty;
            if (obj != null && obj[0] != null)
            {
                if (billTypeField != null)
                {
                    if (((KeyedCollectionBase<string, DynamicProperty>)(object)obj.DynamicObjectType.Properties).ContainsKey(((AbstractElement)billTypeField).Key))
                    {
                        if (obj[((AbstractElement)billTypeField).Key] != null)
                        {
                            text = obj[((AbstractElement)billTypeField).Key].ToString();
                        }
                    }
                    else
                    {
                        object value = ((BaseDataField)billTypeField).RefIDDynamicProperty.GetValue(obj);
                        if (value != null)
                        {
                            text = value.ToString();
                        }
                    }
                }
                if (billStatusField != null)
                {
                    if (((KeyedCollectionBase<string, DynamicProperty>)(object)obj.DynamicObjectType.Properties).ContainsKey(((AbstractElement)billStatusField).Key))
                    {
                        if (obj[((AbstractElement)billStatusField).Key] != null)
                        {
                            text2 = obj[((AbstractElement)billStatusField).Key].ToString();
                        }
                    }
                    else
                    {
                        object fieldValue = ((Field)billStatusField).GetFieldValue(obj);
                        if (fieldValue != null)
                        {
                            text2 = fieldValue.ToString();
                        }
                    }
                }
            }
            if (evetnProxyView != null)
            {
                DynamicFormViewPlugInProxy service = evetnProxyView.GetService<DynamicFormViewPlugInProxy>();
                BeforePrintValidateEventArgs val = new BeforePrintValidateEventArgs(new string[1] { billId });
                service.FireBeforePrintValidate(val);
                if (val.ValidateInfos != null && val.ValidateInfos.Count > 0)
                {
                    result = PrintServiceHelper.ValidatePrintControl(((AbstractDynamicFormPlugIn)this).View.Context, formBusinessInfo, text, text2, val.ValidateInfos[0]);
                }
            }
            else
            {
                result = PrintServiceHelper.ValidatePrintCount(((AbstractDynamicFormPlugIn)this).View.Context, formBusinessInfo, billId, text, text2);
            }
            return result;
        }

        private DynamicObjectCollection GetStatusBillTypeObjs(string[] billIds, BillTypeField billTypeField, BillStatusField billStatusField, Field billNoField)
        {
            Form form = formBusinessInfo.GetForm();
            string pkFieldName = form.PkFieldName;
            if (ObjectUtils.IsNullOrEmpty((object)pkFieldName))
            {
                return null;
            }
            QueryBuilderParemeter val = new QueryBuilderParemeter();
            val.FormId = ((AbstractElement)form).Id;
            val.SelectItems.Add(new SelectorItemInfo(pkFieldName));
            if (billTypeField != null && !ObjectUtils.IsNullOrEmpty((object)((Field)billTypeField).FieldName))
            {
                val.SelectItems.Add(new SelectorItemInfo(((AbstractElement)billTypeField).Key));
            }
            if (billStatusField != null && !ObjectUtils.IsNullOrEmpty((object)((Field)billStatusField).FieldName))
            {
                val.SelectItems.Add(new SelectorItemInfo(((AbstractElement)billStatusField).Key));
            }
            if (billNoField != null && !ObjectUtils.IsNullOrEmpty((object)billNoField.FieldName))
            {
                val.SelectItems.Add(new SelectorItemInfo(((AbstractElement)billNoField).Key));
            }
            string empty = string.Empty;
            SqlParam item;
            if ((int)form.PkFieldType == 2)
            {
                item = new SqlParam("@FID", (KDDbType)162, (object)billIds);
                empty = "2";
            }
            else
            {
                item = new SqlParam("@FID", (KDDbType)161, (object)billIds);
                empty = "1";
            }
            string sqlWithCardinality = StringUtils.GetSqlWithCardinality(billIds.Distinct().Count(), "@FID", int.Parse(empty), true);
            List<ExtJoinTableDescription> extJoinTables = val.ExtJoinTables;
            ExtJoinTableDescription val2 = new ExtJoinTableDescription();
            val2.FieldName = "FID";
            val2.JoinOption = (QueryBuilderParemeter.JoinOption)1;
            val2.ScourceKey = pkFieldName;
            val2.TableName = sqlWithCardinality;
            val2.TableNameAs = "TmpBillPk";
            extJoinTables.Add(val2);
            val.SqlParams.Add(item);
            return QueryServiceHelper.GetDynamicObjectCollection(((AbstractDynamicFormPlugIn)this).View.Model.Context, val, (List<SqlParam>)null);
        }

        private bool SelectTemplateParm()
        {
            bool result = false;
            if (SettingInfo != null)
            {
                foreach (Dictionary<string, object> item in (List<object>)(object)SettingInfo)
                {
                    if (item.ContainsKey("showSelectTemplate"))
                    {
                        bool.TryParse(item["showSelectTemplate"].ToString(), out result);
                        break;
                    }
                }
            }
            return result;
        }

        private IDynamicFormView CreateView(Context ctx, string formId)
        {
            FormMetadata metadata = (FormMetadata)MetaDataServiceHelper.Load(ctx, formId, true);
            ListOpenParameter val = CreateOpenParameter((OperationStatus)1, ctx, formId, metadata);
            IResourceServiceProvider listServiceProvider = GetListServiceProvider((DynamicFormOpenParameter)(object)val);
            object service = listServiceProvider.GetService(typeof(IDynamicFormView));
            IListViewService val2 = (IListViewService)((service is IListViewService) ? service : null);
            ((IDynamicFormViewService)val2).Initialize((DynamicFormOpenParameter)(object)val, listServiceProvider);
            return (IDynamicFormView)val2;
        }

        private IResourceServiceProvider GetListServiceProvider(DynamicFormOpenParameter param)
        {
            FormServiceProvider val = new FormServiceProvider();
            val.Add(typeof(IDynamicFormView), (object)CreateListView(param));
            val.Add(typeof(DynamicFormViewPlugInProxy), (object)new ListViewPlugInProxy());
            val.Add(typeof(DynamicFormModelPlugInProxy), (object)new ListModelPlugInProxy());
            val.Add(typeof(IDynamicFormModelService), (object)GetListModel(param));
            val.Add(typeof(IListFilterModelService), (object)GetListFilterModel());
            Type orRegister = TypesContainer.GetOrRegister("Kingdee.BOS.Business.DynamicForm.DefaultValue.DefaultValueCalculator,Kingdee.BOS.Business.DynamicForm");
            val.Add(typeof(IDefaultValueCalculator), Activator.CreateInstance(orRegister));
            orRegister = TypesContainer.GetOrRegister("Kingdee.BOS.Business.DynamicForm.DBModel.DBModelService,Kingdee.BOS.Business.DynamicForm");
            val.Add(typeof(IDBModelService), Activator.CreateInstance(orRegister));
            return (IResourceServiceProvider)(object)val;
        }

        private object GetListFilterModel()
        {
            Type orRegister = TypesContainer.GetOrRegister("Kingdee.BOS.Model.ListFilter.ListFilterModel,Kingdee.BOS.Model");
            return (IListFilterModelService)Activator.CreateInstance(orRegister);
        }

        private object GetListModel(DynamicFormOpenParameter param)
        {
            Form form = param.FormMetaData.BusinessInfo.GetForm();
            if (form.FormGroups != null && form.FormGroups.Count > 0)
            {
                Type orRegister = TypesContainer.GetOrRegister("Kingdee.BOS.Model.List.TreeListModel,Kingdee.BOS.Model");
                return (IDynamicFormModelService)Activator.CreateInstance(orRegister);
            }
            Type orRegister2 = TypesContainer.GetOrRegister("Kingdee.BOS.Model.List.ListModel,Kingdee.BOS.Model");
            return (IDynamicFormModelService)Activator.CreateInstance(orRegister2);
        }

        private object CreateListView(DynamicFormOpenParameter param)
        {
            Form form = param.FormMetaData.BusinessInfo.GetForm();
            if (form.FormGroups != null && form.FormGroups.Count > 0)
            {
                Type orRegister = TypesContainer.GetOrRegister("Kingdee.BOS.Web.List.TreeListView,Kingdee.BOS.Web");
                return (IDynamicFormView)Activator.CreateInstance(orRegister);
            }
            Type orRegister2 = TypesContainer.GetOrRegister("Kingdee.BOS.Web.List.ListView,Kingdee.BOS.Web");
            return (IDynamicFormView)Activator.CreateInstance(orRegister2);
        }

        private ListOpenParameter CreateOpenParameter(OperationStatus status, Context ctx, string formId, FormMetadata _metadata)
        {
            ListOpenParameter val = new ListOpenParameter(formId, _metadata.GetLayoutInfo().Id);
            Form form = _metadata.BusinessInfo.GetForm();
            val = new ListOpenParameter(formId, string.Empty);
            ((DynamicFormOpenParameter)val).Context = ctx;
            ((DynamicFormOpenParameter)val).ServiceName = form.FormServiceName;
            ((DynamicFormOpenParameter)val).PageId = Guid.NewGuid().ToString();
            ((DynamicFormOpenParameter)val).FormMetaData = _metadata;
            ((DynamicFormOpenParameter)val).LayoutId = _metadata.GetLayoutInfo().Id;
            val.ListFormMetaData = FormMetaDataCache.GetCachedFormMetaData(ctx, "BOS_List");
            ((DynamicFormOpenParameter)val).SetCustomParameter(FormConst.PlugIns, (object)form.CreateListPlugIns());
            ((DynamicFormOpenParameter)val).SetCustomParameter("filterschemeid", (object)schemeId);
            ((DynamicFormOpenParameter)val).SetCustomParameter("listfilterparameter", (object)new ListRegularFilterParameter());
            ((DynamicFormOpenParameter)val).SetCustomParameter("ShowConfirmDialogWhenChangeOrg", (object)false);
            return val;
        }

        private List<string> GetAllAllowPKs(IListView listView)
        {
            //IL_0075: Unknown result type (might be due to invalid IL or missing references)
            //IL_007f: Expected O, but got Unknown
            DynamicObjectCollection pKData = listView.Model.GetPKData();
            if (pKData == null)
            {
                return new List<string>();
            }
            string[] ar = ((IEnumerable<DynamicObject>)pKData).Select((DynamicObject p) => p[0].ToString()).Distinct().ToArray();
            List<PermissionAuthResult> source = ((IDynamicFormModel)listView.Model).FuncPermissionAuth(ar, "8dfa91ae26774d7ea46b29e29ecb3044", new LocaleValue(new LocaleValue(ResManager.LoadKDString("打印", "002014030031190", (SubSystemType)2, new object[0]))), true);
            Func<string, int> getIndex = delegate (string o)
            {
                int result = -1;
                string[] array = ar;
                foreach (string value in array)
                {
                    if (o.Equals(value))
                    {
                        return Array.IndexOf(ar, value);
                    }
                }
                return result;
            };
            IEnumerable<string> source2 = from p in source
                                          where p.Passed && !ObjectUtils.IsNullOrEmpty((object)p.Id)
                                          orderby getIndex(p.Id)
                                          select p.Id;
            return source2.ToList();
        }

        public IListView CreateListView(Context ctx, string lvFormId, string lvSchemeId)
        {
            Type orRegister = TypesContainer.GetOrRegister("Kingdee.BOS.Web.Utils.WebServiceViewBuilder,Kingdee.BOS.Web");
            object obj = Activator.CreateInstance(orRegister);
            MethodInfo method = obj.GetType().GetMethod("CreateListPrintViewBySchemeId");
            object obj2 = method.Invoke(obj, new object[3] { ctx, lvFormId, lvSchemeId });
            return (IListView)((obj2 is IListView) ? obj2 : null);
        }

        private void SetExportMethodShow(bool isShow)
        {
            ComboFieldEditor control = ((AbstractDynamicFormPlugIn)this).View.GetControl<ComboFieldEditor>("FExportMode");
            Control control2 = ((AbstractDynamicFormPlugIn)this).View.GetControl("FExtractMethodPanel");
            control2.Visible = false;
            List<EnumItem> list = new List<EnumItem>();
            List<EnumItem> list2 = list;
            EnumItem val = new EnumItem();
            val.Value = "1";
            val.Caption = new LocaleValue("");
            list2.Add(val);
            if (isShow)
            {
                actionType = (BackgroudPrintActionType)Convert.ToInt32(((AbstractDynamicFormPlugIn)this).View.Model.GetValue("FActionTypeId"));
                DynamicObject val2 = (DynamicObject)((AbstractDynamicFormPlugIn)this).Model.GetValue("FFormId");
                if (val2 != null)
                {
                    formId = val2["Id"].ToString();
                    formMetaData = FormMetaDataCache.GetCachedFormMetaData(((AbstractDynamicFormPlugIn)this).View.Context, formId);
                    if ((int)actionType == 10)
                    {
                        control2.Visible = true;
                        list = new List<EnumItem>();
                        List<EnumItem> list3 = list;
                        EnumItem val3 = new EnumItem();
                        val3.Value = "2";
                        val3.Caption = new LocaleValue(ResManager.LoadKDString("引出", "002011030005671", (SubSystemType)2, new object[0]));
                        list3.Add(val3);
                        if (((AbstractBusinessMetadata)formMetaData).ModelTypeSubId == 902)
                        {
                            List<EnumItem> list4 = list;
                            EnumItem val4 = new EnumItem();
                            val4.Value = "3";
                            val4.Caption = new LocaleValue(ResManager.LoadKDString("引出所有页", "002014000006877", (SubSystemType)2, new object[0]));
                            list4.Add(val4);
                            List<EnumItem> list5 = list;
                            EnumItem val5 = new EnumItem();
                            val5.Value = "4";
                            val5.Caption = new LocaleValue(ResManager.LoadKDString("引出所有页到一页签", "002014000006878", (SubSystemType)2, new object[0]));
                            list5.Add(val5);
                        }
                    }
                }
            }
            control.SetComboItems(list);
            ((AbstractDynamicFormPlugIn)this).View.UpdateView("FExportMode");
        }

        private bool CheckBillRight(string formId)
        {
            HashSet<string> hashSet = PermissionServiceHelper.IsJoinFuncPermission(((AbstractDynamicFormPlugIn)this).View.Context, (IEnumerable<string>)new string[1] { formId });
            if (!hashSet.Contains(formId))
            {
                return true;
            }
            BusinessObject val = new BusinessObject();
            ((BaseStringItem)val).Id = formId;
            val.PermissionControl = 1;
            BusinessObject val2 = val;
            PermissionAuthResult val3 = PermissionServiceHelper.FuncPermissionAuth(((AbstractDynamicFormPlugIn)this).View.Context, val2, "6e44119a58cb4a8e86f6c385e14a17ad");
            if (!val3.Passed)
            {
                BindSchemeList("");
                ((AbstractDynamicFormPlugIn)this).View.UpdateView();
                ((AbstractDynamicFormPlugIn)this).View.ShowErrMessage(ResManager.LoadKDString("您没有当前单据的查看权限！", "002014000004534", (SubSystemType)2, new object[0]), "", (MessageBoxType)0);
                return false;
            }
            return true;
        }

        private void BindSchemeList(string selFormId)
        {
            ComboFieldEditor control = ((AbstractDynamicFormPlugIn)this).View.GetControl<ComboFieldEditor>("FSchemeId");
            if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace((object)selFormId))
            {
                List<FilterScheme> filterSchemeList = LoadSchemeList(selFormId);
                filterSchemeEnumList = BuildSchemeEnumList(filterSchemeList);
                control.SetComboItems(filterSchemeEnumList);
            }
            else
            {
                filterSchemeEnumList = new List<EnumItem>();
                control.SetComboItems(filterSchemeEnumList);
            }
        }

        private List<EnumItem> BuildSchemeEnumList(List<FilterScheme> filterSchemeList)
        {
            List<EnumItem> list = new List<EnumItem>();
            EnumItem val = new EnumItem();
            val.Value = "";
            val.EnumId = "";
            val.Caption = null;
            list.Add(val);
            if (filterSchemeList != null)
            {
                foreach (FilterScheme filterScheme in filterSchemeList)
                {
                    EnumItem val2 = new EnumItem(new DynamicObject(EnumItem.EnumItemType));
                    val2.Value = filterScheme.Id;
                    val2.EnumId = filterScheme.Id;
                    val2.Caption = new LocaleValue(filterScheme.SchemeDisplayName);
                    list.Add(val2);
                }
            }
            return list;
        }
        /// <summary>
        /// 根据单据ID动态加载过滤方案
        /// </summary>
        /// <param name="formID"></param>
        /// <returns></returns>
        private List<FilterScheme> LoadSchemeList(string formID)
        {
            return BusinessDataServiceHelper.LoadSchemeList(((AbstractDynamicFormPlugIn)this).Context, formID, true, true);
        }
    }
}
